package com.aihuishou.controller;

import com.aihuishou.config.ConfigProperties;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @Author Zhang Jintao
 * @Date 2021/3/20 18:00
 * @Version 1.0
 */
@RestController
@Slf4j
public class ConfigController {

    @Autowired
    private ConfigProperties configProperties;

    @Value("${name}")
    private String name;


    @GetMapping("/name")
    public String getName() {
        return configProperties.getName();
    }

    @GetMapping("/mysql")
    public String getMySQLProperties() {
        return configProperties.toString();
    }

    @GetMapping("/getNewName")
    public void getNewName() throws InterruptedException {

        Config config = ConfigService.getConfig("redis.token");
        while (true) {
            String property = config.getProperty("redis.token.name", null);
            String property1 = config.getProperty("redis.token.foo", null);
            TimeUnit.SECONDS.sleep(1);
            log.info(property);
            log.info(property1);
        }

    }

}
